package org.abacus.dbtojava.impl;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import org.abacus.dbtojava.Config;
import org.abacus.dbtojava.Jdbc;

public class MySQLJdbc extends Jdbc {
	public static final String JDBC = "mysql-jdbc.properties";
	private static final Properties props = new Properties();
	static {
		InputStream inStream = MySQLJdbc.class.getResourceAsStream("/" + JDBC);
		try {
			props.load(inStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			Class.forName(props.getProperty(Config.DRIVER_CLASS_NAME));
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public Connection createConnection() {
		try {
			return DriverManager.getConnection(props.getProperty(Config.URL).toString(), props.getProperty(Config.PASSWORD).toString(), props
					.getProperty(Config.PASSWORD).toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
